/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package newspaper;

import entity.News;
import java.io.IOException;
import java.net.UnknownHostException;
import java.util.logging.Level;
import java.util.logging.Logger;
import model.NewsModel;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import util.SocketContentHandle;

/**
 * 
 * @author xuanhung2401
 */
public class VnexpressURL extends Thread {

	static Document doc = null;
	Elements allLink = null;
	private static NewsModel newsModel = new NewsModel();
	private static String site = "http://vnexpress.net/";

	public VnexpressURL(Elements links) {
		allLink = links;
		this.start();
	}

	@Override
	public void run() {
		for (Element e : allLink) {
			String u = e.attr("href");
			// Get link from site (have not http) length more than 4.
			if (u.matches("^((?!http).)*$") && u.split("/").length > 4) {
				String myUrl = "http://" + site + u;
				if (!newsModel.isExits(myUrl)) {
					News n = new News();
					n.setUrl(myUrl);
					n.setSource(site);
					n.setSourceName("VnExpress");
					n.setComplete(false);
					newsModel.save(n);
				}
			}
		}
	}
}
